
package com.wyzz.hr.action;

import java.util.ArrayList;
import java.util.List;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.base.DWRUtil;
import com.wyzz.hr.bo.IDepartmentBO;
import com.wyzz.hr.bo.IEmployeeBo;
import com.wyzz.hr.bo.IPositionBaseBo;
import com.wyzz.hr.pojo.PositionBase;
import com.wyzz.hr.spring.SpringBeanFactory;

public class DWRForChoosePostionDiv extends BaseAction {

	public DWRForChoosePostionDiv() {
	}

	public List getPositionTreeList() {
		List nodeList = new ArrayList();
		Integer status = Integer.valueOf(1);
		IDepartmentBO deptBo = (IDepartmentBO) SpringBeanFactory
				.getBean("departmentBO");
		List activeDepts = deptBo
				.setDeptOfNodeList(nodeList, status.intValue());
		IPositionBaseBo pbBo = (IPositionBaseBo) SpringBeanFactory
				.getBean("positionBaseBo");
		pbBo.setPbOfNodeList(activeDepts, nodeList, status.intValue());
		return nodeList;
	}

	public String judgePositionBase(String pbId) {
		String result = "noauth";
		String auth = DWRUtil.checkAuth("AddRecruitplanInit", "executeInit");
		if ("error".equals(auth))
			return result;
		IPositionBaseBo pbBO = (IPositionBaseBo) getBean("positionBaseBo");
		PositionBase pbNo = pbBO.loadPb(pbId, null);
		if (pbNo != null)
			if (pbNo.getPbMaxEmployee() == null)
				result = "0";
			else
				result = pbNo.getPbMaxEmployee().toString();
		IEmployeeBo empBo = (IEmployeeBo) SpringBeanFactory.getBean("empBo");
		List empListByPb = empBo.getPbActiveEmpNos(pbNo.getId());
		int activeEmpNum = empListByPb.size();
		result = (new StringBuilder()).append(result).append("-").append(
				activeEmpNum).toString();
		int lackNum = 0;
		if (pbNo.getPbMaxEmployee() == null) {
			lackNum = 0;
		} else {
			lackNum = pbNo.getPbMaxEmployee().intValue() - activeEmpNum;
			if (lackNum < 0)
				lackNum = 0;
		}
		result = (new StringBuilder()).append(result).append("-").append(
				lackNum).toString();
		return result;
	}

	private static final long serialVersionUID = 1L;
}
